require('src/index.html');
require('../css/package-index.scss');
require('swiper/dist/css/swiper.css');
require('swiper/dist/js/swiper.js');

var Preloader = require('preloader.js');

/**
 * init
 */
function init () {
  getInfo();
  var mySwiper = new Swiper('#o2_swiper', {
    direction: 'vertical',
    onTouchStart: function (swiper) {
      if (swiper.activeIndex === 0 || swiper.activeIndex === 7) {
        console.log('onTouchStart');
        mySwiper.lockSwipes();
      }
    },
    onTouchEnd: function (swiper) {
      if (swiper.swipeDirection === 'prev') { // 上一页
        if (swiper.activeIndex === 0) {
          page1.leave();
        } else if (swiper.activeIndex === 1) {
          page2.leave();
        } else if (swiper.activeIndex === 2) {
          page3.leave();
        } else if (swiper.activeIndex === 3) {
          page4.leave();
        } else if (swiper.activeIndex === 4) {
          page5.leave();
        } else if (swiper.activeIndex === 5) {
          page6.leave();
        }else if (swiper.activeIndex === 6) {
          page7.leave();
        } else if (swiper.activeIndex === 7) {
          page8.leave(function () {
            mySwiper.unlockSwipes();
            mySwiper.slidePrev(true, 500);
          });
        }
      } else if (swiper.swipeDirection === 'next') { // 下一页
        if (swiper.activeIndex === 0) {
          page1.leave(function () {
            mySwiper.unlockSwipes();
            mySwiper.slideNext(true, 500); // 滑动到下一个
            page2.enter();
          });
        } else if (swiper.activeIndex === 1) {
          page2.leave(function () {
            mySwiper.unlockSwipes();
            page3.enter();
          });
        } else if (swiper.activeIndex === 2) {
          page3.leave(function () {
            mySwiper.unlockSwipes();
            page4.enter();
          });
        } else if (swiper.activeIndex === 3) {
          page4.leave(function () {
            mySwiper.unlockSwipes();
            page5.enter();
          });
        } else if (swiper.activeIndex === 4) {
          page5.leave(function () {
            mySwiper.unlockSwipes();
            page6.enter();
          });
        } else if (swiper.activeIndex === 5) {
          page6.leave(function () {
            mySwiper.unlockSwipes();
            page7.enter();
          });
        } else if (swiper.activeIndex === 6) {
          page7.leave(function () {
            mySwiper.unlockSwipes();
            page8.enter();
          });
        }
      }
    }
  });
}

/**
 * 获取用户信息
 */
function getInfo () {
  var info = JSON.parse(sessionStorage.getItem("info"));
  var hotel = JSON.parse(sessionStorage.getItem("hotel"));
  // 再次判空处理，防止直接访问index.html
  if ((info != 'undefined' && info != null) && (hotel != 'undefined' && hotel != null)) {
    $("#name").text(info.name); // 姓名
    $("#receptionist").text(info.receptionist); // 接待人
    $("#receptionPhone").text(info.receptionPhone); // 接待人
    // 到达信息
    if(info.arriveTime == ""  || info.arriveSite == "") {
      $("#arrived").hide();
    } else {
      $("#comeMsg").text(info.comeMsg);
      $("#arriveTime").text(info.arriveTime);
      $("#arriveSite").text(info.arriveSite);
    }
    // 离开信息
    if(info.leaveTime == ""  || info.leaveSite == "") {
      $("#leaved").hide();
    } else {
      $("#leaveMsg").text(info.leaveMsg);
      $("#leaveTime").text(info.leaveTime);
      $("#leaveSite").text(info.leaveSite);
    }
    // 交通信息
    // $("#strTransportType").text(info.strTransportType);
    // 酒店信息
    $("#hotelName").text(hotel.name); // 酒店名称
    $("#hotelAddress").text(hotel.address); // 酒店地址
    $("#hotelLinkman").text(hotel.hotelLinkman); // 酒店联系人
    $("#linkmanPhone").text(hotel.linkmanPhone); // 酒店联系人电话
    $("#contactNumber").text(hotel.contactNumber); // 酒店座机电话
    // 就餐信息
    $("#fifteenDinner").text(info.fifteenDinner); // 15号晚餐
    $("#breakfast").text(info.breakfast); // 16号早餐
    $("#sixteenLunch").text(info.sixteenLunch); // 16号午餐
    $("#sixteenDinner").text(info.sixteenDinner); // 16号晚餐
    info.sixteenDinnerNo && $("#sixteenDinnerNo").text('（桌号：' + info.sixteenDinnerNo + ')'); // 16号晚餐
  } else {
    console.log("获取行程数据失败！");
    window.location.href='login.html';
  }
}

/**
 * page1
 */
var page1 = {};
page1.enter = function () {
  $('.page-1-logo')
    .addClass('animated bounceInDown');
  $('.page-1-title, .page-1-txt')
    .addClass('animated bounceInLeft');
  $('.page-1-sign')
    .addClass('animated bounceInRight');
}
page1.leave = function (done) {
  done && done();
}

var page2 = {};
page2.enter = function () {
  $('.page-2-info')
    .addClass('animated zoomIn');
}
page2.leave = function (done) {
  $('.page-2-info')
    .removeClass('animated zoomIn');
  done && done();
}

var page3 = {};
page3.enter = function () {
  $('.page-3-info')
    .addClass('animated zoomIn');
}
page3.leave = function (done) {
  $('.page-3-info')
    .removeClass('animated zoomIn');
  done && done();
}

var page4 = {};
page4.enter = function () {
  $('.page-4-info')
    .addClass('animated zoomIn');
}
page4.leave = function (done) {
  $('.page-4-info')
    .removeClass('animated zoomIn');
  done && done();
}

var page5 = {};
page5.enter = function () {
  $('.page-5-info')
    .addClass('animated zoomIn');
}
page5.leave = function (done) {
  $('.page-5-info')
    .removeClass('animated zoomIn')
  done && done();
}

var page6 = {};
page6.enter = function () {
  $('.page-6-info')
    .addClass('animated zoomIn');
}
page6.leave = function (done) {
  $('.page-6-info')
    .removeClass('animated zoomIn')
  done && done();
}

var page7 = {};
page7.enter = function () {
  $('.page-7-info')
    .addClass('animated zoomIn');
}
page7.leave = function (done) {
  $('.page-7-info')
    .removeClass('animated zoomIn')
  done && done();
}

var page8 = {};
page8.enter = function () {
  $('.page-8-info')
    .addClass('animated zoomIn');
}
page8.leave = function (done) {
  $('.page-8-info')
    .removeClass('animated zoomIn')
  done && done();
}

/**
 * preloader && start
 */
var preloader = new Preloader({
  resources: [],
  perMinTime: 1000 // 加载每个资源所需的最小时间，一般用来测试 loading
})
preloader.addCompletionListener(function () {
  $('#o2_main').removeClass('hide');
  Zepto(function($){
    $("#o2_loading").hide();
    page1.enter();
  });
  init();
})
preloader.start();

